package com.example.demo.redis.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.common.domain.CommonResult;
import com.example.demo.redis.service.RedisUserServiceImpl;

@RestController
@RequestMapping("/redis")
public class RedisController {
    private static final Logger logger = LoggerFactory.getLogger(RedisController.class);
    
    @Autowired
    private RedisUserServiceImpl redisUserServiceImpl;

//    private RedisTemplate<String, String> redisTemplate;
//
//    public RedisController(RedisTemplate<String, String> redisTemplate) {
//        this.redisTemplate = redisTemplate;
//    }

    /**
     * 模拟发布订阅功能
     * 当前服务为发布能力
     * MessageSubscriber类提供了订阅的能力
     * @param message
     */
    @GetMapping("/publish")
    public CommonResult publish(@RequestParam String message) {
        // 发送消息
        logger.info("Publish message : " + message);
//        redisTemplate.convertAndSend(RedisMessageSubscriber.CHANNEL, message);
        return CommonResult.ok();
    }

    @GetMapping("/test/{age}")
    public CommonResult jdbcTemplate(@PathVariable Integer age){
        return CommonResult.ok(redisUserServiceImpl.findByAgeTest(age));
    }
}
